package com.jml.springsecurity.core.social.qq.config;

import com.jml.springsecurity.core.properties.QQProperties;
import com.jml.springsecurity.core.properties.SecurityProperties;
import com.jml.springsecurity.core.social.qq.connect.QQConnectionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.social.SocialAutoConfigurerAdapter;
import org.springframework.context.annotation.Configuration;
import org.springframework.social.connect.ConnectionFactory;


@Configuration
@ConditionalOnProperty(prefix = "jml.security.social.qq", name = "app-id")
//只有在系统中配置了appid和appsecurity这个配置才会生效，否则这个配置表不会生效
public class QQAutoConfig extends SocialAutoConfigurerAdapter {

	@Autowired
	private SecurityProperties securityProperties;


	@Override
	protected ConnectionFactory<?> createConnectionFactory() {
		QQProperties qqConfig = securityProperties.getSocial().getQq();
		return new QQConnectionFactory(qqConfig.getProviderId(), qqConfig.getAppId(), qqConfig.getAppSecret());
	}

}
